<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table>
        <thead>
            <tr>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>

    <script>
        const res = {
            headInfo: {
                id: '序号',
                age: '年龄',
                name: '姓名',
            },
            data: [
                {
                    id: 1,
                    name: 'zhangsan',
                    age: 18,
                },
                {
                    id: 2,
                    name: 'lisi',
                    age: 21,
                },
                {
                    id: 3,
                    name: 'wangwu',
                    age: 32,
                },
                {
                    id: 4,
                    name: 'liuliu',
                    age: 22,
                },
            ],
        };

        function render (res) {
            const fields = Object.keys(res.headInfo);
            const headValues = Object.values(res.headInfo);
            document.querySelector('thead tr').innerHTML = headValues.map(v => `<th>${ v }</th>`).join('');
            document.querySelector('tbody').innerHTML = res.data.map(d => `
                <tr>
                    ${ fields.map(f => `<td>${ d[f] }</td>`).join('') }
                </tr>
            `).join('');
        }

        render(res);

    </script>
</body>
</html>